package com.intelligence.pda.ui.abnormal;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentUris;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.hardware.Camera;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.view.ContextThemeWrapper;
import android.support.v7.widget.PopupMenu;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.intelligence.androidlibrary.rxjava.RxBus;
import com.intelligence.androidlibrary.utils.LogUtil;
import com.intelligence.androidlibrary.utils.SharePreferenceUtils;
import com.intelligence.pda.R;
import com.intelligence.pda.event.PendingEvent;
import com.intelligence.pda.parameter.AbnormalSaveParameter;
import com.intelligence.pda.retrofit.ApiCallback;
import com.intelligence.pda.ui.BaseActivity;
import com.intelligence.pda.ui.abnormal.adapter.PhotographAdapter;
import com.intelligence.pda.ui.abnormal.model.AbnormalModel;
import com.intelligence.pda.ui.abnormal.model.PhotographModel;
import com.intelligence.pda.ui.abnormal.model.UploadPictureModel;
import com.intelligence.pda.ui.signout.model.LoginOutModel;
import com.intelligence.pda.utils.AppConstants;
import com.intelligence.pda.utils.ImgUtils;
import com.soundcloud.android.crop.Crop;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;


public class AbnormalActivity extends BaseActivity implements View.OnClickListener {
    @Bind(R.id.ll_toolbar_return)
    LinearLayout ll_toolbar_return;
    @Bind(R.id.tv_toolbar_title)
    TextView tv_toolbar_title;
    @Bind(R.id.et_Order)
    EditText et_Order;
    @Bind(R.id.et_Customer)
    EditText et_Customer;
    @Bind(R.id.ll_source)
    LinearLayout ll_source;
    @Bind(R.id.ll_type)
    LinearLayout ll_type;
    @Bind(R.id.tv_type)
    TextView tv_type;
    @Bind(R.id.add_content)
    EditText add_content;
    @Bind(R.id.gv_Photograph)
    GridView gv_Photograph;
    @Bind(R.id.tv_Submit)
    TextView tv_Submit;
    @Bind(R.id.tv_source)
    TextView tv_source;
    public String OrderNo;
    public String extnorderNo;
    public List<AbnormalModel> abnormalModels1;
    public List<AbnormalModel> abnormalModels2;
    public String condensed1;
    public String condensed2;
    public List<PhotographModel> photographModels;
    private PhotographAdapter photographAdapter = null;

    protected static final int CHOOSE_PICTURE = 0;
    protected static final int TAKE_PICTURE = 1;
    private static final int CROP_SMALL_PICTURE = 6907;
    protected static Uri tempUri;
    private int flag;
    private int sheets = 4;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_abnormal);
        tv_toolbar_title.setText("异常登记");
        Intent intent = getIntent();
        if (intent != null) {
            OrderNo = intent.getStringExtra(AppConstants.ORDER_NO);
            extnorderNo = intent.getStringExtra(AppConstants.EXTNORDER_NO);
            if(!TextUtils.isEmpty(OrderNo)){
                et_Order.setFocusable(false);
            }
            if(!TextUtils.isEmpty(extnorderNo)){
                et_Customer.setFocusable(false);
            }
            et_Order.setText(OrderNo);
            et_Customer.setText(extnorderNo);
        }
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        abnormalModels1 = new ArrayList<>();
        abnormalModels2 = new ArrayList<>();
        photographModels = new ArrayList<>();
        datas();
        getPhotograph();
        photographAdapter = new PhotographAdapter(this);
        gv_Photograph.setAdapter(photographAdapter);
        photographAdapter.addData(photographModels);

        initView();
        listener();
    }

    private void initView() {
        et_Order.requestFocus();
        et_Order.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                if (i == keyEvent.KEYCODE_ENTER && keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getCharacters() != null) {
                    et_Order.setText(keyEvent.getCharacters());
                    return true;
                }
                return false;
            }
        });

        gv_Photograph.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (!TextUtils.isEmpty(photographModels.get(position).getOriImageIds())) {
                    Intent intent = new Intent(mActivity, DialogActivity.class);
                    intent.putExtra("POHOTOR", photographModels.get(position).getOriImageIds());
                    startActivity(intent);
                } else {
                    flag = position;
                    showChoosePicDialog();
                }


            }
        });

        gv_Photograph.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

                if (!TextUtils.isEmpty(photographModels.get(position).getOriImageIds())) {
                    photographModels.remove(position);
                    photographAdapter.addData(photographModels);
                }
                return false;
            }
        });

    }

    private void listener() {
        ll_toolbar_return.setOnClickListener(this);
        ll_source.setOnClickListener(this);
        ll_type.setOnClickListener(this);
        tv_Submit.setOnClickListener(this);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_toolbar_return:
                finish();
                break;
            case R.id.ll_source:
                setDislistPopupMenu1(tv_source);
                break;
            case R.id.ll_type:
                setDislistPopupMenu2(tv_type);
                break;
            case R.id.tv_Submit:
                getabnormalSave();
                break;

        }

    }


    /**
     * 拍照的对话框
     */
    protected void showChoosePicDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("选择照片方式");
        String[] items = {"选择本地照片", "拍照"};
        builder.setNegativeButton("取消", null);
        builder.setItems(items, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (!isCamera()) {
                    cameraTipDialog(mActivity);
                    return;
                }
                if(!isGrantExternalRW(mActivity)){
                    toastShow("请允许使用存储！设置步骤：安全中心-权限管理-按应用管理-PDA-存储-允许");
                    return;
                }
                switch (which) {
                    case CHOOSE_PICTURE: // 选择本地照片
                        Intent openAlbumIntent = new Intent(Intent.ACTION_GET_CONTENT);
                        openAlbumIntent.setType("image/*");
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                            //添加这一句表示对目标应用临时授权该Uri所代表的文件
                            openAlbumIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        }
                        File outDirs = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                        if (!outDirs.exists()) {
                            outDirs.mkdirs();
                        }
                        File outFiles = new File(outDirs, System.currentTimeMillis() + ".jpg");
                        // 把文件地址转换成Uri格式
                        tempUri = getUriForFile(mActivity,outFiles);

                        startActivityForResult(openAlbumIntent, CHOOSE_PICTURE);
                        break;
                    case TAKE_PICTURE: // 拍照

                        // 指定相机拍摄照片保存地址
                        String state = Environment.getExternalStorageState();
                        if (state.equals(Environment.MEDIA_MOUNTED)) {
                            Intent intent = new Intent();
                            // 指定开启系统相机的Action
                            intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
                            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);


                            File outDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
                            if (!outDir.exists()) {
                                outDir.mkdirs();
                            }
                            File outFile = new File(outDir, System.currentTimeMillis() + ".jpg");
                            // 把文件地址转换成Uri格式
                            tempUri = getUriForFile(mActivity,outFile);
                            LogUtil.d("getAbsolutePath=" + outFile.getAbsolutePath());
                            // 设置系统相机拍摄照片完成后图片文件的存放地址
                            intent.putExtra(MediaStore.EXTRA_OUTPUT, tempUri);
                            // 此值在最低质量最小文件尺寸时是0，在最高质量最大文件尺寸时是１
                            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);



                            startActivityForResult(intent, TAKE_PICTURE);

                        } else {
                            Toast.makeText(mActivity, "请确认已经插入SD卡", Toast.LENGTH_LONG).show();

                        }

                        break;
                }
            }
        });
        builder.create().show();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            // 如果返回码是可以用的
            switch (requestCode) {
                case TAKE_PICTURE:
                    Crop.of(tempUri, tempUri).asSquare().withMaxSize(300, 300).start(mActivity, CROP_SMALL_PICTURE);
                    break;
                case CHOOSE_PICTURE:
                    Crop.of(data.getData(), tempUri).asSquare().withMaxSize(300, 300).start(mActivity, CROP_SMALL_PICTURE);
                    break;
                case CROP_SMALL_PICTURE:
                    if (data != null) {
                        setImageToView(data); // 让刚才选择裁剪得到的图片显示在界面上
                    }
                    break;
            }
        }
    }

    /**
     * 保存裁剪之后的图片数据
     *
     * @para
     */
    protected void setImageToView(Intent data) {
        Bundle extras = data.getExtras();
        Bitmap bitmap = null;

        try {
            bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(tempUri));
            Log.d("size", bitmap.getByteCount() + "");
            uploadPic(bitmap);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (extras != null) {
            // bitmap = extras.getParcelable("data");
            // Log.d("size",bitmap.getByteCount()+"");

            /*
             * ByteArrayOutputStream stream = new ByteArrayOutputStream();
             * bitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);
             * byte[] b = stream.toByteArray(); // 将图片流以字符串形式存储下来
             *
             * tp = new String(Base64Coder.encodeLines(b));
             * 这个地方大家可以写下给服务器上传图片的实现，直接把tp直接上传就可以了， 服务器处理的方法是服务器那边的事了，吼吼
             *
             * 如果下载到的服务器的数据还是以Base64Coder的形式的话，可以用以下方式转换 为我们可以用的图片类型就OK啦...吼吼
             * Bitmap dBitmap = BitmapFactory.decodeFile(tp);
             * Drawable drawable = new BitmapDrawable(dBitmap);
             */
        }
    }

    private void uploadPic(Bitmap bitmap) {
        // 上传至服务器
        // ... 可以在这里把Bitmap转换成file，然后得到file的url，做文件上传操作
        String imagePath = ImgUtils.savePhoto(bitmap, Environment
                .getExternalStorageDirectory().getAbsolutePath(), String
                .valueOf(System.currentTimeMillis()));
        photographModels.get(flag).setBitmap(bitmap);
        getNewPrduct(bitmap);

    }

    //以下是关键，原本uri返回的是file:///...来着的，android4.4返回的是content:///...
    @SuppressLint("NewApi")
    public static String getPath(final Context context, final Uri uri) {

        final boolean isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;

        // DocumentProvider
        if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
            // ExternalStorageProvider
            if (isExternalStorageDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                if ("primary".equalsIgnoreCase(type)) {
                    return Environment.getExternalStorageDirectory() + "/" + split[1];
                }

            }
            // DownloadsProvider
            else if (isDownloadsDocument(uri)) {
                final String id = DocumentsContract.getDocumentId(uri);
                final Uri contentUri = ContentUris.withAppendedId(
                        Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

                return getDataColumn(context, contentUri, null, null);
            }
            // MediaProvider
            else if (isMediaDocument(uri)) {
                final String docId = DocumentsContract.getDocumentId(uri);
                final String[] split = docId.split(":");
                final String type = split[0];

                Uri contentUri = null;
                if ("image".equals(type)) {
                    contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
                } else if ("video".equals(type)) {
                    contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
                } else if ("audio".equals(type)) {
                    contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
                }

                final String selection = "_id=?";
                final String[] selectionArgs = new String[]{
                        split[1]
                };

                return getDataColumn(context, contentUri, selection, selectionArgs);
            }
        }
        // MediaStore (and general)
        else if ("content".equalsIgnoreCase(uri.getScheme())) {
            // Return the remote address
            if (isGooglePhotosUri(uri))
                return uri.getLastPathSegment();

            return getDataColumn(context, uri, null, null);
        }
        // File
        else if ("file".equalsIgnoreCase(uri.getScheme())) {
            return uri.getPath();
        }

        return null;
    }

    /**
     * Get the value of the data column for this Uri. This is useful for
     * MediaStore Uris, and other file-based ContentProviders.
     *
     * @param context       The context.
     * @param uri           The Uri to query.
     * @param selection     (Optional) Filter used in the query.
     * @param selectionArgs (Optional) Selection arguments used in the query.
     * @return The value of the _data column, which is typically a file path.
     */
    public static String getDataColumn(Context context, Uri uri, String selection,
                                       String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = {
                column
        };

        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                final int index = cursor.getColumnIndexOrThrow(column);
                return cursor.getString(index);
            }
        } finally {
            if (cursor != null)
                cursor.close();
        }
        return null;
    }


    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is ExternalStorageProvider.
     */
    public static boolean isExternalStorageDocument(Uri uri) {
        return "com.android.externalstorage.documents".equals(uri.getAuthority());
    }

    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is DownloadsProvider.
     */
    public static boolean isDownloadsDocument(Uri uri) {
        return "com.android.providers.downloads.documents".equals(uri.getAuthority());
    }

    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is MediaProvider.
     */
    public static boolean isMediaDocument(Uri uri) {
        return "com.android.providers.media.documents".equals(uri.getAuthority());
    }

    /**
     * @param uri The Uri to check.
     * @return Whether the Uri authority is Google Photos.
     */
    public static boolean isGooglePhotosUri(Uri uri) {
        return "com.google.android.apps.photos.content".equals(uri.getAuthority());
    }

    /**
     * 判断摄像头是否被禁
     */
    public static boolean isCamera() {
        boolean canUse = true;
        Camera camera = null;
        try {
            camera = Camera.open();
        } catch (Exception var3) {
            canUse = false;
        }
        if (canUse) {
            camera.release();
            camera = null;
        }
        return canUse;
    }

    /**
     * 摄像头被禁提示
     *
     * @param context
     */
    public static void cameraTipDialog(Context context) {
        AlertDialog.Builder builder = getAlertDialogBuilder(context);
        builder.setTitle("提示");
        builder.setMessage("请允许使用相机！设置步骤：安全中心-权限管理-按应用管理-PDA-相机-允许");
        builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
            }
        });
        builder.show();
    }

    /**
     * @param context
     * @return
     */
    public static AlertDialog.Builder getAlertDialogBuilder(Context context) {
        AlertDialog.Builder builder;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            builder = new AlertDialog.Builder(context, android.R.style.Theme_Material_Light_Dialog_Alert);
        } else {
            builder = new AlertDialog.Builder(context);
        }
        return builder;
    }

    //解决Android 7.0之后的Uri安全问题
    private Uri getUriForFile(Context context, File file) {
        if (context == null || file == null) {
            throw new NullPointerException();
        }
        Uri uri;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            uri = FileProvider.getUriForFile(mActivity, mActivity.getPackageName() + ".fileprovider", file);

        } else {
            uri = Uri.fromFile(file);
        }
        return uri;
    }
    public static boolean isGrantExternalRW(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && activity.checkSelfPermission(
                Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {

            activity.requestPermissions(new String[]{
                    Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE
            }, 1);

            return false;
        }

        return true;
    }

    /**
     * 转化成数据流、上传图片会用到
     **/
    private MultipartBody.Part getPictureBody(String path) {
        File picture = new File(path);
        RequestBody requestFile = RequestBody.create(MediaType.parse("multipart/form-data"), picture);
        MultipartBody.Part picture_body = MultipartBody.Part.createFormData("uploadPicture", picture.getName(), requestFile);
        return picture_body;
    }

    //上传图片
    private void getNewPrduct(Bitmap bitmap) {
        showProgressDialog();
        String imagePath = ImgUtils.savePhoto(bitmap, Environment.getExternalStorageDirectory().getAbsolutePath(), String.valueOf(System.currentTimeMillis()));
        addSubscription(apiStores.getuploadPicture(getPictureBody(imagePath)),
                new ApiCallback<UploadPictureModel>() {
                    @Override
                    public void onSuccess(UploadPictureModel model) {
                        if (photographModels.size() < sheets) {
                            PhotographModel photographModel = new PhotographModel();
                            photographModel.setName("添加图片");
                            photographModel.setImg(R.mipmap.ic_pic);
                            photographModels.add(photographModel);

                        }

                        photographModels.get(flag).setOriImageIds(model.getData().getImageId());
                        photographAdapter.addData(photographModels);

                    }

                    @Override
                    public void onFailure(UploadPictureModel model, String msg) {
                        toastShow(msg);
                    }

                    @Override
                    public void onFailure(String msg) {
                        toastShow(msg);

                    }


                    @Override
                    public void onFinish() {
                        dismissProgressDialog();
                    }

                });
    }


    public void getabnormalSave() {

        if (TextUtils.isEmpty(et_Order.getText().toString())) {
            toastShow("请填写订单号");
            return;
        }
        if (TextUtils.isEmpty(et_Customer.getText().toString())) {
            toastShow("请填写客户单单号");
            return;
        }
        if (TextUtils.isEmpty(condensed1)) {
            toastShow("请选择异常来源");
            return;
        }
        if (TextUtils.isEmpty(condensed2)) {
            toastShow("请选择异常类型");
            return;
        }

        if (photographModels.size() == 0) {
            toastShow("至少拍一张照片");
            return;
        }


        AbnormalSaveParameter abnormalSaveParameter = new AbnormalSaveParameter();
        abnormalSaveParameter.setOrderNo(et_Order.getText().toString());
        abnormalSaveParameter.setExtnOrderNo(et_Customer.getText().toString());
        abnormalSaveParameter.setStockType(condensed1);
        abnormalSaveParameter.setType(condensed2);
        List<String> oriImageIds = new ArrayList<>();
        for (int i = 0; i < photographModels.size(); i++) {
            oriImageIds.add(photographModels.get(i).getOriImageIds());
        }
        abnormalSaveParameter.setOriImageIds(oriImageIds);
        abnormalSaveParameter.setBasicStr(SharePreferenceUtils.getString(AppConstants.BASIC_STR));
        showProgressDialog();
        addSubscription(apiStores.getabnormalSave(abnormalSaveParameter),
                new ApiCallback<LoginOutModel>() {
                    @Override
                    public void onSuccess(LoginOutModel model) {
                        toastShow("异常登记提交成功");
                        //发送事件

                        PendingEvent pendingEvent=new PendingEvent();
                        pendingEvent.setOrderNo(et_Order.getText().toString());
                        RxBus.getInstance().post(pendingEvent);


                        dismissProgressDialog();
                        finish();
                    }

                    @Override
                    public void onFailure(LoginOutModel model, String msg) {
                        toastShow(msg);
                        dismissProgressDialog();
                    }

                    @Override
                    public void onFailure(String msg) {
                        toastShow(msg);
                        dismissProgressDialog();
                    }


                    @Override
                    public void onFinish() {
                        dismissProgressDialog();
                    }

                });


    }


    private void setDislistPopupMenu1(View view) {
        Context wrapper = new ContextThemeWrapper(mActivity, R.style.PopupMenuStyles);
        final PopupMenu popupMenu = new PopupMenu(wrapper, view);
        for (int i = 0; i < abnormalModels1.size(); i++) {
            popupMenu.getMenu().add(0, i, 0, abnormalModels1.get(i).getName()).setTitleCondensed(abnormalModels1.get(i).getCondensed());
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                LogUtil.d(item.getTitle() + "," + item.getTitleCondensed());
                condensed1 = item.getTitleCondensed().toString();
                tv_source.setText(item.getTitle().toString());
                return true;
            }
        });
        popupMenu.show();
    }

    private void setDislistPopupMenu2(View view) {
        Context wrapper = new ContextThemeWrapper(mActivity, R.style.PopupMenuStyles);
        final PopupMenu popupMenu = new PopupMenu(wrapper, view);
        for (int i = 0; i < abnormalModels2.size(); i++) {
            popupMenu.getMenu().add(0, i, 0, abnormalModels2.get(i).getName()).setTitleCondensed(abnormalModels2.get(i).getCondensed());
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                LogUtil.d(item.getTitle() + "," + item.getTitleCondensed());
                condensed2 = item.getTitleCondensed().toString();
                tv_type.setText(item.getTitle().toString());
                return true;
            }
        });
        popupMenu.show();
    }

    public void datas() {
        //异常来源（入库：01.in；出库：02.out；）
        // 异常类型（少件：01.missing,多件：02.excessive,货损：03.damage,其他：04.others）
        AbnormalModel abnormalModel = new AbnormalModel();
        abnormalModel.setName("入库");
        abnormalModel.setCondensed("01.in");
        abnormalModels1.add(abnormalModel);
        AbnormalModel abnormalModel2 = new AbnormalModel();
        abnormalModel2.setName("出库");
        abnormalModel2.setCondensed("02.out");
        abnormalModels1.add(abnormalModel2);

        AbnormalModel abnormalModel3 = new AbnormalModel();
        abnormalModel3.setName("少件");
        abnormalModel3.setCondensed("01.missing");
        abnormalModels2.add(abnormalModel3);
        AbnormalModel abnormalModel4 = new AbnormalModel();
        abnormalModel4.setName("多件");
        abnormalModel4.setCondensed("02.excessive");
        abnormalModels2.add(abnormalModel4);
        AbnormalModel abnormalModel5 = new AbnormalModel();
        abnormalModel5.setName("货损");
        abnormalModel5.setCondensed("03.damage");
        abnormalModels2.add(abnormalModel5);
        AbnormalModel abnormalModel6 = new AbnormalModel();
        abnormalModel6.setName("其他");
        abnormalModel6.setCondensed("04.others");
        abnormalModels2.add(abnormalModel6);

    }

    public void getPhotograph() {
        PhotographModel photographModel = new PhotographModel();
        photographModel.setName("添加图片");
        photographModel.setImg(R.mipmap.ic_pic);
        photographModels.add(photographModel);

    }
}
